package com.czl.module_storehouse.mvp.model;

import com.czl.base.data.bean.tengyun.CategoryBean;
import com.czl.base.data.bean.tengyun.SortBean;
import com.czl.base.data.net.RetrofitClient;
import com.czl.base.util.SpHelper;
import com.czl.module_base.bean.CompanyBean;
import com.czl.module_base.http.HttpResponse;
import com.czl.module_base.mvp.model.BaseModel;
import com.czl.module_service.system.Constants;
import com.czl.module_storehouse.api.ApiService;
import com.google.gson.JsonArray;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.Arrays;
import java.util.List;

import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * @author by xubin,
 * @date on 2022/2/11.
 * PS: Not easy to write code, please indicate.
 */
public class CategoryModel extends BasicDataModel {

    public Observable<HttpResponse<List<CategoryBean>>> getclassificationlistCompany() {
        JSONObject object = new JSONObject();
        try {
            object.put("companyId", getManageCompanyId());
//            object.put("companyId",     getCompanyId());
            JSONArray array = new JSONArray();
            array.put(0);
            array.put(1);
            array.put(2);
            object.put("classStatusList", array);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String json = object.toString();
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        return RetrofitClient.getInstance().create(ApiService.class)
                .getclassificationlistCompany(RequestBody.create(mediaType, json));
    }

    public Observable<HttpResponse<List<CategoryBean>>> getclassificationlistCompany(String propCompanyId) {
       return getclassificationlistCompany(propCompanyId, Arrays.asList(0, 1, 2));
    }

    public Observable<HttpResponse<List<CategoryBean>>> getclassificationlistCompany(String propCompanyId, List<Integer> classStatus) {
        JSONObject object = new JSONObject();
        try {
            object.put("companyId", getManageCompanyId());
            object.put("propCompanyId", propCompanyId);
            JSONArray array = new JSONArray();
            for (Integer integer : classStatus) {
                array.put(integer);
            }
            object.put("classStatusList", array);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String json = object.toString();
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        return RetrofitClient.getInstance().create(ApiService.class)
                .getclassificationlistCompany(RequestBody.create(mediaType, json));
    }

    public Observable<HttpResponse<List<CategoryBean>>> getclassificationlistCompany(Integer propCompanyId, SortBean sortBean, List<Integer> classStatus) {
        JSONObject object = new JSONObject();
        try {
            object.put("propCompanyId", propCompanyId);
            object.put("companyId", getManageCompanyId());
            JSONArray array = new JSONArray();
            if (classStatus != null && !classStatus.isEmpty()) {
                for (Integer value : classStatus) {
                    array.put(value);
                }
            }
            object.put("classStatusList", array);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String json = object.toString();
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        return RetrofitClient.getInstance().create(ApiService.class)
                .getclassificationlistCompany(RequestBody.create(mediaType, json));
    }

    public Observable<HttpResponse<List<CategoryBean>>> getclassificationlistCompany(Integer propCompanyId, String pIdPath, List<Integer> classStatus) {
        JSONObject object = new JSONObject();
        try {
            object.put("propCompanyId", propCompanyId);
            object.put("companyId", getManageCompanyId());
            JSONArray array = new JSONArray();
            if (classStatus != null && !classStatus.isEmpty()) {
                for (Integer value : classStatus) {
                    array.put(value);
                }
            }
            object.put("classStatusList", array);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String json = object.toString();
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");

        return RetrofitClient.getInstance().create(ApiService.class)
                .getclassificationlistCompany(RequestBody.create(mediaType, json));
    }

    public Observable<HttpResponse<List<CategoryBean>>> getClassStockList(Integer propCompanyId) {
        JSONObject object = new JSONObject();
        try {
            object.put("companyId", getManageCompanyId());
            object.put("propCompanyId", propCompanyId);
            JsonArray array = new JsonArray();
            array.add(getStorehouseId());
            object.put("storehouseIdList", array);
            JsonArray array1 = new JsonArray();
            array1.add(0);
            array1.add(1);
            array1.add(2);
            object.put("classStatusList", array1);
//            object.put("stockInfo", 1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String json = object.toString();
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        return RetrofitClient.getInstance().create(ApiService.class)
                .getClassStockList(RequestBody.create(mediaType, json));
    }
}
